<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\KnowledgeArticleFeatured;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class KnowledgeArticleFeaturedController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new KnowledgeArticleFeatured(), function (Grid $grid) {
            $grid->model()->orderBy('sort', 'desc');
            $grid->column('id')->sortable();
            $grid->column('img')->image('http://static.i.wedoctors.com.cn/', 100, 100);

            $grid->url('url');
            $grid->column('sort')->sortable('sort')->editable(true);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new KnowledgeArticleFeatured(), function (Show $show) {
            $show->field('id');
            $show->field('sort');
            $show->field('img');
            $show->field('url');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new KnowledgeArticleFeatured(), function (Form $form) {
            $form->display('id');
            $form->image('img','图片')
                ->uniqueName()
                ->autoUpload()
                ->accept('jpg,png,gif,jpeg', 'image/*')
                ->maxSize(500)->disk('oss');
            $form->text('url');
            $form->number('sort');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
